<?php
defined('IN_APPS') or die('Go away...');

class BlogModel extends Model {
	
	protected $name = 'blogs';
	
	/**
	 * Get all published posts
	 */
	public function getPublished()
	{
		// create SQL statement
		$sql = "SELECT * FROM " . $this->tableName . " WHERE published = 1";
		
		// run mysql_query
		$query = mysql_query($sql);
		
		$result = array();
		
		if ($query) {
			// if success
			while ($row = mysql_fetch_array($query)) {
				$result[] = $row;
			}
			
			return $result;
		}
		else {
			// if error
			die('Error: ' . mysql_error());
		}
	}
	
	
	/**
	 * Get all published posts
	 */
	public function getUnpublished()
	{
		// create SQL statement
		$sql = "SELECT * FROM " . $this->tableName . " WHERE published = 0";
		
		// run mysql_query
		$query = mysql_query($sql);
		
		$result = array();
		
		if ($query) {
			// if success
			while ($row = mysql_fetch_array($query)) {
				$result[] = $row;
			}
			
			return $result;
		}
		else {
			// if error
			die('Error: ' . mysql_error());
		}
	}
	
}